#include "dbtabuser.h"
#include "databasequery.h"
const QLatin1String DBTabUser::TAB_NAME = QLatin1String("user_new");
const char* DBTabUser::_USER_NAME = "user_name";
const char* DBTabUser::_PINYIN = "pinyin";
const char* DBTabUser::_USER_CODE = "user_code";
const char* DBTabUser::_PASSWD = "password";
const char* DBTabUser::_PERMISSION = "permission";
const char* DBTabUser::_PHONE_NUM = "phone_num";
const char* DBTabUser::_ADDRESS = "address";



void DBTabUser::createTab(QSqlDatabase &db)
{
    DataBaseQuery query(db);
    //query.exec("drop table " + TAB_NAME);
    QString str = "CREATE TABLE "+TAB_NAME +"(\n" +
            _ID + " integer primary key "AUTO_INCREMENT",\n"+
            _USER_NAME + " varchar(" +QString::number(USERNAME_LEN)+")" + " NOT NULL,\n"+
            _PINYIN + " varchar(128),\n" +
            _USER_CODE + " varchar(" +QString::number(10)+"),\n" +
            _PASSWD + " varchar(64) ,\n" +
            _PERMISSION + " INT ,\n" +
            _PHONE_NUM + " varchar(64) , \n" +
            _ADDRESS + " TEXT -- description \n"+
            ") -- 用户表\n";
    qDebug()<<str;
    if(query.exec(str)==false)
    {
         qDebug()<<" create " +  TAB_NAME + " error ";
    }

}

DBTabUser::DBTabUser():DBTabBase(TAB_NAME)
{}
